package v1

import (
	"github.com/gin-gonic/gin"
	"guns-go/model/request"
	"guns-go/model/response"
	"guns-go/service"
)

// @Tags Position
// @Summary 职位列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SysPosParam true "请求参数"
// @Success 200 {string} string "{"success":true,"data":{},"message":"请求成功","code":200}"
// @Router /sysPos/list [get]
func SysPosList(c *gin.Context) {

	var S request.SysPosParam
	_ = c.ShouldBindQuery(&S)

	err, sysPosSlice := service.SysPosList(&S)

	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.OkWithData(sysPosSlice, c)
}

// @Tags Position
// @Summary 职位分页查询
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SysPosParam true "请求参数"
// @Success 200 {string} string "{"success":true,"data":{},"message":"请求成功","code":200}"
// @Router /sysPos/page [get]
func PosPage(c *gin.Context) {

	var P request.SysPosParam
	_ = c.ShouldBindQuery(&P)

	err, PosPageResult := service.PosPage(&P, c)

	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.OkWithData(PosPageResult, c)
}

// @Tags Position
// @Summary 职位新增
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SysPosParam true "请求参数"
// @Success 200 {string} string "{"success":true,"data":{},"message":"请求成功","code":200}"
// @Router /sysPos/add [post]
func PosAdd(c *gin.Context) {

	var P request.SysPosParam
	_ = c.ShouldBindJSON(&P)

	err := service.PosAdd(&P)

	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.Ok(c)
}

// @Tags Position
// @Summary 职位修改
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SysPosParam true "请求参数"
// @Success 200 {string} string "{"success":true,"data":{},"message":"请求成功","code":200}"
// @Router /sysPos/edit [post]
func PosEdit(c *gin.Context) {

	var P request.SysPosParam
	_ = c.ShouldBindJSON(&P)

	err := service.PosEdit(&P)

	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.Ok(c)
}

// @Tags Position
// @Summary 职位删除
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SysPosParam true "请求参数"
// @Success 200 {string} string "{"success":true,"data":{},"message":"请求成功","code":200}"
// @Router /sysPos/delete [post]
func PosDelete(c *gin.Context) {

	var P request.SysPosParam
	_ = c.ShouldBindJSON(&P)

	err := service.PosDelete(&P)

	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.Ok(c)
}
